#lang planet neil/sicp

(define make-queue
  (let ((queue (cons '() '()))
        (front-ptr car)
        (rear-ptr cdr))
    (define (set-front-ptr! item) 
      (set-car! queue item))
    (define (set-rear-ptr! item) 
      (set-cdr! queue item))
    (define (empty-queue?) 
      (null? (front-ptr queue)))
    (define (front-queue)
      (if (empty-queue?)
          (error "FRONT called with an 
              empty queue" queue)
          (car (front-ptr queue))))
    (define (insert-queue! item)
      (let ((new-pair (cons item '())))
        (cond ((empty-queue?)
               (set-front-ptr! new-pair)
               (set-rear-ptr! new-pair)
               queue)
              (else (set-cdr! (rear-ptr queue) 
                              new-pair)
                    (set-rear-ptr! new-pair)
                    queue))))
    (define (delete-queue!)
      (cond ((empty-queue?)
             (error "DELETE! called with 
                 an empty queue" queue))
            (else (set-front-ptr! 
                   (cdr (front-ptr queue)))
                  queue)))
    (define (dispatch m)
      (cond ((eq? m 'delete) delete-queue!)
            ((eq? m 'insert) insert-queue!)
            ((eq? m 'empty) empty-queue?)))
    dispatch))

(define q1 make-queue)

((q1 'insert) 'a)
((q1 'insert) 'b)
((q1 'delete))
((q1 'delete))